home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-22 | 4.4 KB | 113 lines | [TEXT/CCL2] |
- ;
- ; think-ref-lookup.lisp
- ;
- ; This code enables you to lookup THINK Reference (TM) from Fred editor.
- ; If you load this file, the lookup function ed-think-reference is bound to m-r.
- ;
- ; The Original code is posted to info-mcl@cambridge.apple.com on 12/1/1993
- ; by Jeffrey B Kane (jbk@world.std.com).
- ; I added some faculties
- ; * to launch THINK Reference (TM) if you have not loaded it yet.
- ; * to get the current S expression and lookup if it is a symbol.
- ; * to handle appleevent-error and display its message to mini-buffer.
- ;
- ; And on Bill St. Clair's (bill@cambridge.apple.com) advice, I changed my code
- ; to search THINK Reference (TM) with _PBDTGetAPPL. I referd to his code
- ; in the file cambridge.apple.com /pub/mcl2/contrib/processes.lisp.
- ;
- ; Special thanks for Jeffery and Bill.
- ;
- ; Masaya UEDA ueda@shpcsl.sharp.co.jp
-
- (eval-when (:compile-toplevel :execute :load-toplevel)
- (require :appleevent-toolkit))
-
- (defun get-creator-path-aux (creator fsspec)
- (let ((devs (directory "*:")))
- (dolist (vrefnum (sort (mapcar 'volume-number devs) #'>))
- (rlet ((pb :DTPBRec
- :ioNamePtr (%null-ptr)
- :ioVRefnum vrefnum))
- (when (= (#_PBDTGetPath pb) #$noErr)
- (setf (rref pb :DTPBRec.ioNamePtr)
- (%inc-ptr fsspec (get-field-offset :fsspec.name))
- (pref pb :DTPBRec.ioIndex) 0
- (pref pb :DTPBRec.ioFileCreator) creator)
- (when (= (#_PBDTGetAPPL pb) #$noErr)
- (setf (pref fsspec :fsspec.vRefnum) vrefnum
- (pref fsspec :fsspec.parID) (pref pb :DTPBRec.ioAPPLParID))
- (return (values))))))))
-
- (defun get-creator-path (creator)
- (rlet ((fsspec :fsspec))
- (get-creator-path-aux creator fsspec)
- (%path-from-fsspec fsspec)))
-
- (defun launch-application-aux (sfFile)
- (rlet ((lpb :LaunchParamBlockRec
- :launchBlockID #$extendedBlock
- :launchEPBLength #$extendedBlockLen
- :launchFileFlags 0
- :launchControlFlags (+ #$launchContinue #$launchNoFileFlags)
- :launchAppSpec sfFile
- :launchAppParameters (%null-ptr)))
- (if (= (#_LaunchApplication lpb) #$noErr)
- (values (rref lpb :LaunchParamBlockRec.launchProcessSN.highLongOfPSN)
- (rref lpb :LaunchParamBlockRec.launchProcessSN.LowLongOfPSN)))))
-
- (defun launch-application (filename &aux (pf (probe-file filename)))
- (if pf
- (rlet ((fsspec :FSSpec))
- (with-pstrs ((name (mac-namestring pf)))
- (#_FSMakeFSSpec 0 0 name fsspec))
- (launch-application-aux fsspec))))
-
- (defun Think-Ref (search-string)
- (flet ((strlen (cstring)
- (if (macptrp cstring)
- (let ((n 0))
- (loop
- (if (= (%get-byte cstring n) 0)
- (return n)
- (incf n))))
- nil)))
- (with-aedescs (ae target reply)
- (with-cstrs ((my-cstring search-string))
- (multiple-value-bind (psnhigh psnlow) (find-process-with-signature :|DanR|)
- (unless psnhigh
- (multiple-value-setq (psnhigh psnlow)
- (rlet ((fsspec :fsspec))
- (get-creator-path-aux :|DanR| fsspec)
- (launch-application-aux fsspec))))
- (when psnhigh
- (create-psn-target target psnhigh psnlow)
- ;; create an apple event
- (ae-error (#_AECreateAppleEvent
- :|DanR|
- :|REF |
- target
- #$kAutoGenerateReturnID
- #$kAnyTransactionID
- ae))
- ;; stuff it with our parameters
- (ae-error (#_AEPutParamPtr
- ae
- #$keyDirectObject
- #$typeChar
- my-cstring
- (strlen my-cstring)))
- ;; send it off
- (send-appleevent ae reply :reply-mode :wait-reply)))))))
-
- (defmethod ed-think-reference ((fm fred-mixin))
- (let ((sym (ed-current-sexp fm)))
- (when (and sym (symbolp sym))
- (let ((sn (symbol-name sym)))
- (when (or (char= #\_ (char sn 0)) (char= #\$ (char sn 0)))
- (setq sn (subseq sn 1)))
- (handler-case (Think-Ref sn)
- (appleevent-error (condition)
- (format (view-mini-buffer fm) "~a: ~a"
- sym condition)))))))
-
- (def-fred-command (:meta #\r) ed-think-reference)